package acm.pta14;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

public class 拼题A打卡奖励 {
    public static void main(String[] args) {
        Reader sc = new Reader();
        int n = sc.nextInt();
        int total = sc.nextInt();
        int[] time = new int[n];
        int[] val = new int[n];
        int sum= 0;
        for (int i = 0; i < time.length; i++) {
            time[i] = sc.nextInt();
            sum+=time[i];
        }
        for (int i = 0; i < time.length; i++) {
            val[i] = sc.nextInt();
        }
//        System.out.println(fun(time, val, n - 1, total));
        int[] dp = dpFun(time, val, sum);
        for (int i = dp.length - 1; i >= 0; i--) {
            if (total>= i){
                System.out.println(dp[i]);
                break;
            }
        }
//        System.out.println(dpFun(time, val, total));
    }

    public static int[] dpFun(int[] time, int[] val, int sum) {
        int[] dp = new int[sum+ 1];
        for (int i = 1; i <= sum; i++) {

        }
        for (int i = 1; i < dp.length; i++) {
            for (int j = 0; j < time.length; j++) {
                if (i >= time[j]) {
                    dp[i] = Math.max(dp[i], dp[i - time[j]] + val[j]);
                }
            }
        }
        return dp;
    }

    public static int fun(int[] time, int[] val, int i, int total) {
        if (i < 0) return 0;
        int no = fun(time, val, i - 1, total);
        if (total < time[i]) return no;
        int take = fun(time, val, i - 1, total - time[i]);
        return Math.max(take + val[i], no);
    }

    static class Reader {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (Exception ignored) {
            }
            return (int) in.nval;
        }
    }
}
